/**
 *
 */
package com.vivi.codereview.tools;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author nvillard
 *
 */
public final class Utils {

  private static final String DATE_FORMAT = "dd-MMM-yyyy HH:mm.ss z";

  private static final SimpleDateFormat sdf;

  static {
    sdf = new SimpleDateFormat(DATE_FORMAT);
  }

  public static String formatString(String pattern, String... vars) throws Exception {
    String output = pattern;
    for (int i = 0; i < vars.length; i++) {
      // We use this strange way to replace Strings to don't use regexp
      StringBuilder old = new StringBuilder();
      old.append("{");
      old.append(i);
      old.append("}");
      while (output.contains(old)) {
        output = output.replace(old, vars[i]);
      }
    }
    return output;
  }

  public static String getCurrentDateTime() {
    return sdf.format(new Date(System.currentTimeMillis()));
  }

}
